Updating a Database Using Flash MX Professional 2004
Table of Contents
The Basics
Before I get too deep into the technical details, I'd like to discuss some of the basics about the concepts and components you'll be dealing with.
Terminology
Throughout this article, I am using the following terms:
- DeltaPacket: An object produced by a DataSet component that contains a list of the changes that were made to its data.
- update packet: An XML document that describes the content of a DeltaPacket. I discuss the format of this (and the following) XML document in detail in this tutorial.
- result packet: An XML document that contains the results of the operations in the corresponding update packet.
- server function: Code residing on a server in the form of an ASP page, a Java servlet, a ColdFusion component, and so on. The sample ColdFusion component that is part of this tutorial's sample files provides an example of this functionality.
What Are Resolvers and How Do They Work with DataSets?
In Flash MX Professional 2004, resolvers are essentially two-way translators between a DataSet and the outside world. To remain as flexible as possible, the DataSet only understands DeltaPackets. If you want to store changes to a dataset persistently, you must use a resolver to turn the DeltaPacket into a more useful form.
Every resolver understands how to break down a DeltaPacket and extract the information within it. Each type of resolver produces a different translation of that information. For example, the XUpdateResolver translates DeltaPackets into XUpdate, a language for updating XML.
The RDBMSResolver Component
In this article I use the RDBMSResolver component to send the changes in a dataset to a ColdFusion component that parses it into SQL and saves it to a SQL database.
Why bother going thru the extra step of sending the DeltaPacket to a component like this CFC? Why not bypass the component and have the resolver produce SQL? Two reasons: There are too many variants of SQL, each with its own slight differences in syntax, field formatting requirements, and so on. Also, for the DataSet component to function properly, it needs to receive results that contain transaction IDs and operation IDs so that individual results can be matched with the row from which they originated. SQL syntax does not support this functionality.
So, instead of producing SQL, the RDBMSResolver component produces XML in a format that can be easily parsed and turned into SQL in the required dialect. The same server function that parses it can individually apply operations to the database, determine the result of each, and return a result packet containing them.